/*
 * MixTask_test.cpp
 *
 *  Created on: 22 gru 2013
 *      Author: dawid.wysakowicz
 */

#include "threads/MixTask.hpp"
#include "threads/threadPool.hpp"
#include "gtest_wrapper.hpp"

namespace threads
{

TEST(Pool, simple)
{
	ThreadPool pool(3);

	dna::marker locus1;
	locus1.push_back(dna::allel('A'));
	locus1.push_back(dna::allel('A'));
	locus1.push_back(dna::allel('A'));
	locus1.push_back(dna::allel('B'));

	dna::marker locus2;
	locus2.push_back(dna::allel('A'));
	locus2.push_back(dna::allel('A'));
	locus2.push_back(dna::allel('B'));
	locus2.push_back(dna::allel('B'));

	dna::marker locus3;
	locus3.push_back(dna::allel('A'));
	locus3.push_back(dna::allel('B'));
	locus3.push_back(dna::allel('B'));
	locus3.push_back(dna::allel('B'));

	std::mutex resultGuard;
	std::list<dna::genotypeSet> results;

	MixTask task1(locus1, results, resultGuard);
	MixTask task2(locus2, results, resultGuard);
	MixTask task3(locus3, results, resultGuard);

	pool.run_task<MixTask>(task1);
	pool.run_task<MixTask>(task2);
	pool.run_task<MixTask>(task3);

	pool.wait();

	ASSERT_EQ(7, results.size())<< "wrong variants count!";

	std::vector<std::string> expected = { "(A,A)(A,B)", "(A,B)(A,A)", "(A,A)(B,B)", "(A,B)(A,B)", "(B,B)(A,A)", "(A,B)(B,B)", "(B,B)(A,B)"};
	std::for_each(results.begin(), results.end(),
			[&expected] (const dna::genotypeSet& collection)
			{

				std::stringstream str;
				std::for_each(collection.begin(), collection.end(),
						[&str](const dna::genotype& gen)
						{
							str << gen;
						});
				EXPECT_TRUE(std::find(expected.begin(), expected.end(), str.str().c_str()) != expected.end()) << "Bad results: " << str.str();
			});
}

} /* namespace threads */
